home *** CD-ROM | disk | FTP | other *** search
- /*
- * Simplified version of the standard Internet "finger" program.
- * It fingers the special purpose user "nm_notifyuser" on the computer
- * given as the only argument.
- *
- * This program is meant to be called by the mail delivery program on
- * a POP server. See below for how to invoke it.
- * When fingered with the user name "nm_notifyuser", NotifyMail will
- * tell the POP client to fetch mail from the POP server.
- *
- *
- * It is (normally) invoked as follows:
- * nmfinger <machinename>
- * where machinename is replaced by the IP address or DNS name of the
- * machine running NotifyMail.
- *
- * If NotifyMail is configured to use UDP, this program should be invoked
- * as follows:
- * nmfinger <machinename> UDP
- *
- *
- * It exits with a result code of 0 wether or not the computer
- * replies. It doesn't listen for any answer.
- *
- * Use the options "-D_BSD -lbsd" to compile on AIX 4.1.
- * PATH=/usr/bin:/usr/local/bin gcc -s -O nmfinger.c -o nmfinger -lsocket -lnsl
- *
- * Concept for this program and original prototype written by a NotifyMail user
- * Modifications and redesign by SAG
- */
-
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <sys/errno.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <netdb.h>
- #include <stdio.h>
-
- #define DATA "nm_notifyuser\r\n"
- #define BUFSIZE 256
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int sock, flag;
- struct sockaddr_in server;
- struct hostent *hp;
- char buffer[BUFSIZE];
-
- /* Read and discard data from standard input (the mail). */
-
- /* Under most circumstances, you should leave the following */
- /* line uncommented as the mail will be piped into the stdin of this */
- /* program. However, if you encounter problems, comment out the */
- /* following line. */
-
- while (getc(stdin)!=EOF);
-
-
- /* Create a socket. */
- /* Normally create a TCP socket...if it is invoked for UDP, create a */
- /* UDP socket. */
-
- sock = socket(AF_INET, SOCK_STREAM, 0);
-
- if (sock < 0)
- {
- exit(0);
- }
-
- /* Look up the domain name given as argument. */
- hp = gethostbyname(argv[1]);
- if (hp == 0)
- {
- exit(0);
- }
-
- /*
- * In order to reduce the time we want to wait for the
- * connection to NotifyMail to timeout, we'll do an fping
- * to the host. If the ping returns very quickly, then
- * try the connection. Make sure that fping is
- * properly installed
- */
- strcpy(buffer,"which fping");
-
- if (system(buffer) ==0)
- {
- sprintf(buffer,"fping -q -t 250 %s",argv[1]);
-
- if (system(buffer) != 0)
- {
- exit(0);
- }
- }
-
- /* Build address structure. */
- memcpy(&server.sin_addr,hp->h_addr,hp->h_length);
-
- server.sin_family = AF_INET;
-
- /* The following line may need to be uncommented depending on the OS version -SAG */
- /* server.sin_len = sizeof(server); */
- server.sin_port = htons(atoi("2079"));
-
- /* Connect to machine running NotifyMail. */
- if (connect(sock, (struct sockaddr*)&server, sizeof(server)) < 0)
- {
- exit(0);
- }
-
- /* Send finger request. */
- if (write(sock, DATA, sizeof(DATA)-1) < 0)
- {
- exit(0);
- }
-
- /* Recive answer and throw it away. */
- /* Under most circumstances, you can leave the following block commented */
- /* out; there is no reason to read the response (if any) from NotifyMail. */
- /*
- if (read(sock, buffer, BUFSIZE) < 0)
- {
- exit(0);
- }
- */
-
- /* Close socket. */
- close(sock);
-
- exit(0);
- }
-